package com.yanfan.product.controller;

import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.energy.domain.Batches;
import com.yanfan.energy.domain.BatchesRequest;
import com.yanfan.energy.service.BatchesService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @Author huan
 * @Description 批次管理
 * @ClassName 2023年01月09日 10:30:00
 * @Version 1.0
 **/
@RestController
@RequestMapping("/production/batches")
public class BatchesController {

    @Autowired
    private BatchesService batchesService;

    /**
     * 批次管理页面-批次汇总信息 （页面顶部位置）
     *
     * @return
     */
    @PostMapping("/batchSummary")
    public AjaxResult batchSummary() {
        return AjaxResult.success(batchesService.batchSummary());
    }


    /**
     * 批次管理列表
     *
     * @param request
     * @return
     */
    @PostMapping("/batchesList")
    public AjaxResult batchesList(@RequestBody BatchesRequest request) {
        PageHelper.startPage(request.getCurrPage(), request.getPageSize());
        PageInfo<Batches> pageInfo = new PageInfo<Batches>(batchesService.batchesList(request));
        return AjaxResult.success(pageInfo);
    }

    /**
     * 新增批次
     *
     * @param request
     * @return
     */
    @PostMapping("/addBatches")
    public AjaxResult addBatches(@RequestBody BatchesRequest request) throws Exception {
        return AjaxResult.success(batchesService.addBatches(request));
    }

    /**
     * 修改批次
     *
     * @param request
     * @return
     */
    @PostMapping("/updateBatches")
    public AjaxResult updateBatches(@RequestBody BatchesRequest request) {
        return AjaxResult.success(batchesService.updateBatches(request));
    }


    /**
     * 批次详情
     *
     * @param request
     * @return
     */
    @PostMapping("/batchesDetail")
    public AjaxResult batchesDetail(@RequestBody BatchesRequest request) {
        return AjaxResult.success(batchesService.batchesDetail(request));
    }


    /**
     * 删除批次
     *
     * @param request
     * @return
     */
    @PostMapping("/deleteBatches")
    public AjaxResult deleteBatches(@RequestBody BatchesRequest request) {
        return AjaxResult.success(batchesService.deleteBatches(request));
    }


    /**
     * 查询厂区列表  表名plant
     *
     * @return
     */
    @PostMapping("/factoryList")
    public AjaxResult factoryList() {
        return AjaxResult.success(batchesService.factoryList());
    }


    /**
     * 查询车间列表  表名plant
     *
     * @return
     */
    @PostMapping("/workshopList/{plantId}")
    public AjaxResult workshopList(@PathVariable("plantId") Integer plantId) {
        return AjaxResult.success(batchesService.workshopList(plantId));
    }

    @PostMapping("/managerHome")
    public AjaxResult managerHome() {
        //订单
        return AjaxResult.success(batchesService.managerHome());
    }


}
